******SET YOUR DIRECTORY to ...\replication



clear all
set more off

use "finaldata\final_cc_data.dta", clear

set matsize 2000

drop if fipsplace_00==.
xtset fipsplace_00 year

drop if year>1991

*Create instrument and outcome
g good_soil = (ph1_plc_wtm_wtm_0_r>=6.8 & ph1_plc_wtm_wtm_0_r<=7.7)
gen inter_badtetra=(1-good_soil)*tetra_corr
g perc_cc =  tot_cc_oripop_corr / (tot_ncc_oripop_corr + tot_cc_oripop_corr)
g pop_msa = tot_ncc_oripop_corr + tot_cc_oripop_corr
g lnpop_cc = ln(tot_cc_oripop_corr)
g lnpop_ncc = ln(tot_ncc_oripop_corr)
gen lnpop_msa=ln(pop_msa)

*Create independent variables
gen vc_pc=totnpcc_cc_offenses_vc*1000
gen vc_ncc_pc=totnpcc_ncc_offenses_vc*1000

*Cluster variables
egen cdivcodeyear=group(cdivcode year)

*Label variables
label var vc_pc "Violent crime CC"
label var vc_ncc_pc "Violent crime NCC"
label var good_soil "Low LB"
label var inter_badtetra "High LB x Lead"
label var perc_cc "Sh. Pop CC"
label var lnpop_cc "ln(Pop CC)"
label var lnpop_ncc "ln(Pop NCC)"
label var pop_msa "Pop MSA"
label var lnpop_msa "ln(Pop MSA)"
label var cdivcodeyear "Census Division Code x Year"

*Fix sample of cities with available suburb population
drop if tot_ncc_oripop_corr == .

***First stage
reghdfe vc_pc inter_badtetra, abs(fipsplace_00 year cdivcode#year) cluster(cdivcodeyear)
outreg2 inter_badtetra using table1, tex(frag) nocon noni nor2 nonotes label ctitle("Violent crime CC") addtext(Sample, All, Estimation, OLS, F, .)  replace
***OLS
reghdfe perc_cc vc_pc, abs(fipsplace_00 year cdivcode#year) cluster(cdivcodeyear)
outreg2 vc_pc using table1, tex(frag) nocon noni nor2 nonotes label ctitle("Sh. Pop CC") addtext(Sample, All, Estimation, OLS, F, .) 
***OLS, LATE, omitted variables, crime NCC
reghdfe perc_cc vc_pc vc_ncc_pc if cdivcode==4 | cdivcode==6 | cdivcode==8 | cdivcode==9, abs(fipsplace_00 year cdivcode#year) cluster(cdivcodeyear)
outreg2 vc_pc using table1, tex(frag) nocon noni nor2 nonotes label ctitle("Sh. Pop CC") addtext(Sample, No east, Estimation, OLS, F, .) 
***IV
ivreghdfe perc_cc (vc_pc = inter_badtetra), abs(fipsplace_00 year cdivcode#year) cluster(cdivcodeyear)
local ff= string(round(e(cdf),.01) , "%9.2f")
outreg2 vc_pc using table1, tex(frag) nocon noni nor2 nonotes label ctitle("Sh. Pop CC") addtext(Sample, All, Estimation, IV, F, `ff')  
***IV CC
ivreghdfe lnpop_cc (vc_pc = inter_badtetra), abs(fipsplace_00 year cdivcode#year) cluster(cdivcodeyear)
local ff= string(round(e(cdf),.01) , "%9.2f")
outreg2 vc_pc using table1, tex(frag) nocon noni nor2 nonotes label ctitle("ln(Pop CC)") addtext(Sample, All, Estimation, IV, F, `ff')  
***IV NCC
ivreghdfe lnpop_ncc (vc_pc = inter_badtetra), abs(fipsplace_00 year cdivcode#year) cluster(cdivcodeyear)
local ff= string(round(e(cdf),.01) , "%9.2f")
outreg2 vc_pc using table1, tex(frag) nocon noni nor2 nonotes label ctitle("ln(Pop NCC)") addtext(Sample, All, Estimation, IV, F, `ff')  
***IV MSA
ivreghdfe lnpop_msa (vc_pc = inter_badtetra), abs(fipsplace_00 year cdivcode#year) cluster(cdivcodeyear)
local ff= string(round(e(cdf),.01) , "%9.2f")
outreg2 vc_pc using table1, tex(frag) nocon noni nor2 nonotes label ctitle("ln(Pop MSA)") sortvar(inter_badtetra vc_pc) addtext(Sample, All, Estimation, IV, F, `ff') 
